﻿Public Class ErrorPresentacionDAO

    Public Shared Function insertarErrorPresentacion(ByVal ErrorPresentacionMotivo As Integer, ByVal ErrorPresentacionCorreccion As Integer, ByVal ErrorPresentacionCorregido As Integer, ByVal EmpleadoId As Integer, ByVal TipoErrorPresentacionId As Integer, ByVal PresentacionId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_errorPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionMotivo", ErrorPresentacionMotivo).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorreccion", ErrorPresentacionCorreccion).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorregido", ErrorPresentacionCorregido).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", EmpleadoId).DbType = DbType.Int32
                    .AddWithValue("@TipoErrorPresentacionId", TipoErrorPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@PresentacionId", PresentacionId).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function actualizarErrorPresentacion(ByVal ErrorPresentacionId As Integer, ByVal ErrorPresentacionMotivo As Integer, ByVal ErrorPresentacionCorreccion As Integer, ByVal ErrorPresentacionCorregido As Integer, ByVal EmpleadoId As Integer, ByVal TipoErrorPresentacionId As Integer, ByVal PresentacionId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_errorPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionId", ErrorPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionMotivo", ErrorPresentacionMotivo).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorreccion", ErrorPresentacionCorreccion).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorregido", ErrorPresentacionCorregido).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", EmpleadoId).DbType = DbType.Int32
                    .AddWithValue("@TipoErrorPresentacionId", TipoErrorPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@PresentacionId", PresentacionId).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function eliminarErrorPresentacion(ByVal ErrorPresentacionId As Integer) As Boolean
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim consulta As New SqlClient.SqlCommand
            With consulta
                .CommandText = "usp_errorPresentacion"
                .CommandType = CommandType.StoredProcedure
                With .Parameters
                    .AddWithValue("@Accion", Constante.ACTUALIZAR).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionId", ErrorPresentacionId).DbType = DbType.Int32
                    .AddWithValue("@ErrorPresentacionMotivo", Constante.VACIO).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorreccion", Constante.VACIO).DbType = DbType.String
                    .AddWithValue("@ErrorPresentacionCorregido", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@EmpleadoId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@TipoErrorPresentacionId", Constante.MENOSUNO).DbType = DbType.Int32
                    .AddWithValue("@PresentacionId", Constante.MENOSUNO).DbType = DbType.Int32
                End With
                .Connection = cn
                .ExecuteNonQuery()
            End With
            Return True
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return False
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

    Public Shared Function obtenerErroresPresentaciones(ByVal ErrorPresentacionId As Integer) As DataTable
        Dim cn As SqlClient.SqlConnection = Nothing
        Try
            cn = Conexion.Conectar
            Dim ds As New DataSet
            Dim da As New SqlClient.SqlDataAdapter("usp_errorPresentacion_obtener", cn)
            da.SelectCommand.CommandType = CommandType.StoredProcedure
            da.SelectCommand.Parameters.AddWithValue("@ErrorPresentacionId", ErrorPresentacionId).DbType = DbType.Int32
            da.Fill(ds, "ErrorPresentacion")

            Return ds.Tables("ErrorPresentacion")
        Catch ex As Exception
            'GUARDAMOS EL ERROR EN LA BD
            ErrorDAO.insertarError(ex)
            Return Nothing
        Finally
            Conexion.Desconectar(cn) 'PASAR POR PARAMETRO LA CONEXION
        End Try
    End Function

End Class
